//
//  UIImage+Extension.swift
//  WeiBO28
//
//  Created by 飞奔的羊 on 16/5/20.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
extension UIImage {

	func scaleImageWithWidth(scalWidth: CGFloat) -> UIImage {
		//压缩后的宽 100,你要计算压缩后的高度
		//比方说,图片的大小传入的是 200,300(W,H)
		let scaleHeight = scalWidth / self.size.width * self.size.height
		
		let size = CGSize(width: scalWidth, height: scaleHeight)
		//开启上下文
		UIGraphicsBeginImageContext(size)
		//图片绘制到指定区域
		self.drawInRect(CGRect(origin: CGPointZero, size: size))
		//获取图片
		let scaleImage = UIGraphicsGetImageFromCurrentImageContext()
		
		
		//关闭上下文
		UIGraphicsEndImageContext()
		
		return scaleImage
	}
}
